package org.mathcloud.math.core.generic.operator;

import org.mathcloud.math.core.common.operator.BinaryOperator;
import org.mathcloud.math.core.common.quantity.QuantityObject;
import org.mathcloud.math.core.common.signature.QuantityObjectSignature;
import org.mathcloud.math.core.generic.signature.GenericOperatorObjectSignature;
import org.mathcloud.math.core.generic.signature.GenericQuantityObjectSignature;
import org.webequa.core.generic.operator.GenericOperator;


public abstract class GenericBinaryOperator
	extends GenericOperator implements BinaryOperator
{

	public GenericBinaryOperator()
	{
		super();
		signature = new GenericOperatorObjectSignature(2,null,"generic");
		operand1 = operand2 = null;
	}
	
	@Override
	public void setInputParams(QuantityObject in1, QuantityObject in2)
	{
		operand1 = in1;
		operand2 = in2;
	}

	@Override
	public QuantityObject getOperand(int n)
	{ 
		if (n==1)
			return operand1;
		else if (n==2) return operand2;
		else return null;
	}

	@Override
	public int getOperandOrder()
	{
		return operandOrder;
	}
	
	@Override
	public QuantityObjectSignature getResultSignature()
	{
    if ((operand1!=null)&&(operand2!=null))
    {
      GenericQuantityObjectSignature resSign = (GenericQuantityObjectSignature) 
      	GenericQuantityObjectSignature.getRealNumberSignature();
      if (operand1.getSignature().isComplex()||operand2.getSignature().isComplex())
        resSign.setComplex(true);
      resSign.setDimensionsNumber(Math.max(operand1.getSignature().getDimensionsNumber(),
          operand2.getSignature().getDimensionsNumber()));
      if (resSign.getDimensionsNumber()==operand1.getSignature().getDimensionsNumber())
        resSign.setDimensions(operand1.getSignature().getDimensions());
      else resSign.setDimensions(operand2.getSignature().getDimensions());      
      return resSign;
    } else return null;
	}
	
  protected QuantityObject operand1;
  protected QuantityObject operand2;
  protected int operandOrder;
}
